package com.journaldev.spring.model;

import java.util.Set;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.Table;
import javax.persistence.Transient;

import org.hibernate.annotations.Cascade;


@Entity
@Table(name="thanhpho")
public class City {
	
	
	public City() {
	}
	
	

	public City(int id, String cityName) {
		super();
		this.id = id;
		this.cityName = cityName;
	}



	@Id
	@Column(name="id_thanhpho")
	@GeneratedValue(strategy=GenerationType.IDENTITY)
	private int id;
	
	//orphanRemoval : when set to true , and delete 1 object in set ==> delete that object in db too
	@OneToMany(cascade=CascadeType.ALL, fetch = FetchType.EAGER, mappedBy = "belongToCity", orphanRemoval = true)
	private Set<District> disTrict;
	
	public Set<District> getDisTrict() {
		return disTrict;
	}



	public void setDisTrict(Set<District> disTrict) {
		this.disTrict = disTrict;
	}



	public int getId() {
		return id;
	}

	public void setId(int id) {
		this.id = id;
	}

	@Column(name="ten_thanhpho")
	private String cityName;

	public String getCityName() {
		return cityName;
	}

	public void setCityName(String cityName) {
		this.cityName = cityName;
	}

}
